package com.moyq5.mvc.maker.test.feign.server.jackson.filter;

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;

import com.moyq5.mvc.framework.utils.StringUtils;
import com.moyq5.mvc.maker.test.bean.entity.TraAccount;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;

/**
 * @author Moyq5's MvcMaker Tools
 */
public abstract class TraAccountFilter {

	public static FilterProvider get(String filter) {
		if (StringUtils.isEmpty(filter)) {
				return get();
		}
		try {
				Method method = TraAccount.class.getMethod("getWith" + String.valueOf(filter.charAt(0)).toUpperCase() + filter.substring(1));
				return (FilterProvider)method.invoke(null);
		} catch (Exception e) {
				return get();
		}
	}
	
	public static Set<String> baseFields() {
		final Set<String> account = new HashSet<String>();
		return account;
	}

	public static FilterProvider getId() {
		final Set<String> account = new HashSet<String>();
		account.add("");
		
		return new SimpleFilterProvider().addFilter(
				TraAccount.class.getSimpleName(),
				SimpleBeanPropertyFilter.filterOutAllExcept(account));
	}

	public static FilterProvider get() {
		return new SimpleFilterProvider().addFilter(
				TraAccount.class.getSimpleName(),
				SimpleBeanPropertyFilter.filterOutAllExcept(baseFields()));
	}

}
